﻿#region - Class details -
/*  
 *  Developer   :Tony Hicks
 *  Description : 
 *  History     :
 */
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Linq;

namespace QuickApp.Helpers
{
    public static class General
    {

        #region - Private methods -
        #endregion

        #region - Public methods -
        public static void ChangeAppSetting(string appSettingName, string value)
        {
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            if (!config.AppSettings.Settings.AllKeys.Any(itm => itm == appSettingName))
                config.AppSettings.Settings.Add(appSettingName, value);
            else
                config.AppSettings.Settings[appSettingName].Value = value;
            config.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection("appSettings");
        }

        public static bool IsNumeric(this Type type)
        {
            return type.In(
                typeof(byte), typeof(sbyte), 
                typeof(short), typeof(ushort), 
                typeof(int), typeof(uint), 
                typeof(long), typeof(ulong), 
                typeof(float), typeof(double), typeof(decimal));
        }


        #endregion
    }
}
